package com.zhbr.mvp.ui.fragment;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.zhbr.R;
import com.zhbr.entity.TGdfwPqgd;
import com.zhbr.mvp.base.presenter.BasePresenter;
import com.zhbr.mvp.base.view.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class OrderFragment extends BaseFragment implements OnTabSelectListener {

    private OrderViewModel mViewModel;

    private Context mContext = getContext();
    private ArrayList<BaseFragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "95598" , "主动抢修", "小程序","话务"
    };
    private MyPagerAdapter mAdapter;

    private ViewPager viewPager;
    private SlidingTabLayout slidingTabLayout;

    private List<TGdfwPqgd> list = new ArrayList<>();

    public static OrderFragment newInstance() {
        return new OrderFragment();
    }


    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    public void getViewModel() {
        mViewModel=new ViewModelProvider(this, new ViewModelProvider.NewInstanceFactory()).get(OrderViewModel.class);
    }


    @Override
    public Context getActivityContext() {
        return getContext();
    }

    @Override
    public int getContentView() {
        return R.layout.order_fragment;
    }

    @Override
    public void initView(View view) {
        viewPager = view.findViewById(R.id.fixedViewPager);
        slidingTabLayout = view.findViewById(R.id.slidingTabLayout);
        mAdapter = new MyPagerAdapter(getActivity().getSupportFragmentManager());
    }
    @Override
    public void initData() {
        mFragments.add(PageFragment1.getInstance());
        mFragments.add(PageFragment2.getInstance());
        mFragments.add(PageFragment3.getInstance());
        mFragments.add(PageFragment4.getInstance());
        viewPager.setAdapter(mAdapter);
        slidingTabLayout.setViewPager(viewPager);
        viewPager.setCurrentItem(0);
        viewPager.setOffscreenPageLimit(mTitles.length);
        slidingTabLayout.showDot(0);
        slidingTabLayout.showMsg(0, 5);
    }



    @Override
    public void onTabSelect(int position) {
        showToast("onTabReselect&position--->" + position);
    }

    @Override
    public void onTabReselect(int position) {
        showToast("onTabReselect&position--->" + position);
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }

    /**
     * Return the FragmentManager for interacting with fragments associated
     * with this activity.
     */

}